package com.edu.bhu.admin.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.edu.bhu.admin.mapper.HouHouseAndTagMapper;
import com.edu.bhu.common.core.domain.entity.SysRole;
import com.edu.bhu.common.utils.StringUtils;
import com.edu.bhu.common.utils.spring.SpringUtils;
import com.edu.bhu.system.domain.SysUserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.HouTagMapper;
import com.edu.bhu.admin.domain.HouTag;
import com.edu.bhu.admin.service.IHouTagService;
import com.edu.bhu.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 房屋标签Service业务层处理
 * 
 * @author zhangkeyi
 * @date 2022-02-22
 */
@Service
public class HouTagServiceImpl implements IHouTagService 
{
    @Autowired
    private HouTagMapper houTagMapper;

    /**
     * 查询房屋标签（标签ID）
     *
     * @param tagId 关联标签ID
     * @return 房屋标签
     */
    @Override
    public HouTag selectHouTagByTagId(Long tagId)
    {
        return houTagMapper.selectHouTagByTagId(tagId);
    }

    /**
     * 查询房屋标签（房屋ID），被授予的标签做标记
     *
     * @param houseId 关联房屋ID
     * @return 所有房屋标签
     */
    @Override
    public List<HouTag> selectHouTagByHouseId(Long houseId)
    {
        List<HouTag> houseTags = houTagMapper.selectHouTagByHouseId(houseId);
        List<HouTag> tags = selectTagAll();
        for (HouTag tag : tags)
        {
            for (HouTag houseTag : houseTags)
            {
                if (tag.getTagId().longValue() == houseTag.getTagId().longValue())
                {
                    tag.setFlag(true);
                    break;
                }
            }
        }
        return tags;
    }

    /**
     * 查询房屋标签（房屋ID）
     *
     * @param houseId 关联房屋ID
     * @return 该房屋授予的房屋标签
     */
    public List<HouTag> selectAuthHouTagByHouseId(Long houseId)
    {
        return houTagMapper.selectHouTagByHouseId(houseId);
    }

    /**
     * 查询房屋标签列表
     * 
     * @param houTag 房屋标签
     * @return 房屋标签
     */
    @Override
    public List<HouTag> selectHouTagList(HouTag houTag)
    {
        return houTagMapper.selectHouTagList(houTag);
    }

    /**
     * 查询所有房屋标签
     *
     * @return 房屋标签列表
     */
    @Override
    public List<HouTag> selectTagAll()
    {
        return SpringUtils.getAopProxy(this).selectHouTagList(new HouTag());
    }
    /**
     * 新增房屋标签
     * 
     * @param houTag 房屋标签
     * @return 结果
     */
    @Override
    public int insertHouTag(HouTag houTag)
    {
        return houTagMapper.insertHouTag(houTag);
    }

    /**
     * 修改房屋标签
     * 
     * @param houTag 房屋标签
     * @return 结果
     */
    @Override
    public int updateHouTag(HouTag houTag)
    {
        return houTagMapper.updateHouTag(houTag);
    }

    /**
     * 批量删除房屋标签
     * 
     * @param tagIds 需要删除的房屋标签主键
     * @return 结果
     */
    @Override
    public int deleteHouTagByTagIds(String tagIds)
    {
        return houTagMapper.deleteHouTagByTagIds(Convert.toStrArray(tagIds));
    }

    /**
     * 删除房屋标签信息
     * 
     * @param tagId 房屋标签主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteHouTagByTagId(Long tagId)
    {
        return houTagMapper.deleteHouTagByTagId(tagId);
    }
}
